﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerAttack : MonoBehaviour
{
    private PlayerConllter player;

    void Start()
    {
        player = FindObjectOfType<PlayerConllter>();
    }

    //unity 自带，检测是否在碰撞体内，Stay持续检测
    public void OnTriggerStay2D(Collider2D collision)
    {

        if (collision.gameObject.GetComponent<Enemy>() != null)
        {
            if (collision.gameObject.GetComponent<Enemy>().isEnemy && !collision.gameObject.GetComponent<Enemy>().anim.GetCurrentAnimatorStateInfo(2).IsName("hit"))
            {
                float HP = player.attack;
                collision.gameObject.GetComponent<Enemy>().GetHit(HP);
            }

        }
    }

    //Enter 进入检测
    public void OnTriggerEnter2D(Collider2D collision)
    {
        print("ent");
    }

    //Exit 退出检测
    public void OnTriggerExit2D(Collider2D collision)
    {
        print("exit");
    }
}
